﻿namespace Vdc.Grid.Design
{
    using Vdc.Grid;
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Globalization;

    internal class GridLocalizationSettingsConverter : ExpandableObjectConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                string str = (string) value;
                try
                {
                    string[] strArray = str.Split(new char[] { ',' });
                    GridLocalizationSettings settings = new GridLocalizationSettings();
                    int num = 0;
                    settings.AddLink = strArray[num++];
                    settings.CancelAllLink = strArray[num++];
                    settings.CancelLink = strArray[num++];
                    settings.DeleteLink = strArray[num++];
                    settings.EditLink = strArray[num++];
                    settings.Filter_ApplyLink = strArray[num++];
                    settings.Filter_HideLink = strArray[num++];
                    settings.Filter_RemoveLink = strArray[num++];
                    settings.Filter_ShowLink = strArray[num++];
                    settings.FilterCriteria_Contains = strArray[num++];
                    settings.FilterCriteria_DoesNotContain = strArray[num++];
                    settings.FilterCriteria_EndsWith = strArray[num++];
                    settings.FilterCriteria_EqualTo = strArray[num++];
                    settings.FilterCriteria_GreaterThan = strArray[num++];
                    settings.FilterCriteria_GreaterThanOrEqualTo = strArray[num++];
                    settings.FilterCriteria_IsEmpty = strArray[num++];
                    settings.FilterCriteria_IsNotEmpty = strArray[num++];
                    settings.FilterCriteria_IsNotNull = strArray[num++];
                    settings.FilterCriteria_IsNull = strArray[num++];
                    settings.FilterCriteria_NoFilter = strArray[num++];
                    settings.FilterCriteria_NotEqualTo = strArray[num++];
                    settings.FilterCriteria_SmallerThan = strArray[num++];
                    settings.FilterCriteria_SmallerThanOrEqualTo = strArray[num++];
                    settings.FilterCriteria_StartsWith = strArray[num++];
                    settings.Grouping_GroupInformationNextPage = strArray[num++];
                    settings.Grouping_GroupInformationPreviousNextPage = strArray[num++];
                    settings.Grouping_GroupInformationPreviousPage = strArray[num++];
                    settings.Grouping_GroupingAreaText = strArray[num++];
                    settings.JSWarning = strArray[num++];
                    settings.LoadingText = strArray[num++];
                    settings.MaxLengthValidationError = strArray[num++];
                    settings.ModifyLink = strArray[num++];
                    settings.NoRecordsText = strArray[num++];
                    settings.Paging_ManualPagingLink = strArray[num++];
                    settings.Paging_OfText = strArray[num++];
                    settings.Paging_PageSizeOptions_All = strArray[num++];
                    settings.Paging_PageSizeText = strArray[num++];
                    settings.Paging_PagesText = strArray[num++];
                    settings.Paging_RecordsText = strArray[num++];
                    settings.Paging_TotalNumberOfPages = strArray[num++];
                    settings.Paging_ToText = strArray[num++];
                    settings.RemoveLink = strArray[num++];
                    settings.ResizingTooltipPixels = strArray[num++];
                    settings.ResizingTooltipWidth = strArray[num++];
                    settings.SaveAllLink = strArray[num++];
                    settings.SaveLink = strArray[num++];
                    settings.TypeValidationError = strArray[num++];
                    settings.UndeleteLink = strArray[num++];
                    settings.UpdateLink = strArray[num++];
                    return settings;
                }
                catch (Exception exception1)
                {
                    if (exception1 != null)
                    {
                    }
                }
            }
            return base.ConvertFrom(context, culture, value);
        }

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                return "";
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }

        public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
        {
            return new GridLocalizationSettings { 
                AddLink = propertyValues["AddLink"].ToString(),
                CancelAllLink = propertyValues["CancelAllLink"].ToString(),
                CancelLink = propertyValues["CancelLink"].ToString(),
                DeleteLink = propertyValues["DeleteLink"].ToString(),
                EditLink = propertyValues["EditLink"].ToString(),
                Filter_ApplyLink = propertyValues["Filter_ApplyLink"].ToString(),
                Filter_HideLink = propertyValues["Filter_HideLink"].ToString(),
                Filter_RemoveLink = propertyValues["Filter_RemoveLink"].ToString(),
                Filter_ShowLink = propertyValues["Filter_ShowLink"].ToString(),
                FilterCriteria_Contains = propertyValues["FilterCriteria_Contains"].ToString(),
                FilterCriteria_DoesNotContain = propertyValues["FilterCriteria_DoesNotContain"].ToString(),
                FilterCriteria_EndsWith = propertyValues["FilterCriteria_EndsWith"].ToString(),
                FilterCriteria_EqualTo = propertyValues["FilterCriteria_EqualTo"].ToString(),
                FilterCriteria_GreaterThan = propertyValues["FilterCriteria_GreaterThan"].ToString(),
                FilterCriteria_GreaterThanOrEqualTo = propertyValues["FilterCriteria_GreaterThanOrEqualTo"].ToString(),
                FilterCriteria_IsEmpty = propertyValues["FilterCriteria_IsEmpty"].ToString(), 
                FilterCriteria_IsNotEmpty = propertyValues["FilterCriteria_IsNotEmpty"].ToString(),
                FilterCriteria_IsNotNull = propertyValues["FilterCriteria_IsNotNull"].ToString(),
                FilterCriteria_IsNull = propertyValues["FilterCriteria_IsNull"].ToString(), 
                FilterCriteria_NoFilter = propertyValues["FilterCriteria_NoFilter"].ToString(),
                FilterCriteria_NotEqualTo = propertyValues["FilterCriteria_NotEqualTo"].ToString(),
                FilterCriteria_SmallerThan = propertyValues["FilterCriteria_SmallerThan"].ToString(), 
                FilterCriteria_SmallerThanOrEqualTo = propertyValues["FilterCriteria_SmallerThanOrEqualTo"].ToString(),
                FilterCriteria_StartsWith = propertyValues["FilterCriteria_StartsWith"].ToString(),
                Grouping_GroupInformationNextPage = propertyValues["Grouping_GroupInformationNextPage"].ToString(),
                Grouping_GroupInformationPreviousNextPage = propertyValues["Grouping_GroupInformationPreviousNextPage"].ToString(), 
                Grouping_GroupInformationPreviousPage = propertyValues["Grouping_GroupInformationPreviousPage"].ToString(), 
                Grouping_GroupingAreaText = propertyValues["Grouping_GroupingAreaText"].ToString(), 
                JSWarning = propertyValues["JSWarning"].ToString(),
                LoadingText = propertyValues["LoadingText"].ToString(),
                MaxLengthValidationError = propertyValues["MaxLengthValidationError"].ToString(), 
                ModifyLink = propertyValues["ModifyLink"].ToString(), 
                NoRecordsText = propertyValues["NoRecordsText"].ToString(),
                Paging_ManualPagingLink = propertyValues["Paging_ManualPagingLink"].ToString(),
                Paging_OfText = propertyValues["Paging_OfText"].ToString(),
                Paging_PageSizeOptions_All = propertyValues["Paging_PageSizeOptions_All"].ToString(),
                Paging_PageSizeText = propertyValues["Paging_PageSizeText"].ToString(),
                Paging_PagesText = propertyValues["Paging_PagesText"].ToString(),
                Paging_RecordsText = propertyValues["Paging_RecordsText"].ToString(),
                Paging_TotalNumberOfPages = propertyValues["Paging_TotalNumberOfPages"].ToString(),
                Paging_ToText = propertyValues["Paging_ToText"].ToString(),
                RemoveLink = propertyValues["RemoveLink"].ToString(),
                ResizingTooltipPixels = propertyValues["ResizingTooltipPixels"].ToString(),
                ResizingTooltipWidth = propertyValues["ResizingTooltipWidth"].ToString(), 
                SaveAllLink = propertyValues["SaveAllLink"].ToString(), SaveLink = propertyValues["SaveLink"].ToString(),
                TypeValidationError = propertyValues["TypeValidationError"].ToString(), 
                UndeleteLink = propertyValues["UndeleteLink"].ToString(), 
                UpdateLink = propertyValues["UpdateLink"].ToString()
             };
        }

        public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
        {
            return true;
        }
    }
}

